/*
 * Created by XiaoDongLei
 * Copyright (c) 2017-2017
 * Apache License
 * Version 2.0, January 2004
 * http://www.apache.org/licenses/
 *
 *
 *
 */
package com.chris;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import sun.nio.cs.Surrogate;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
 * @author XiaoDongLei
 * @Package com.chris
 * @date 2018/5/11
 * @Description:
 */
public class GeneratorSqlmap {
	public void generator() throws Exception{

		//MBG 执行过程中的警告信息
		List<String> warnings = new ArrayList<String>();
		//当生成的代码重复时，覆盖原代码
		boolean overwrite = true;
		//指定 逆向工程配置文件
//		File configFile = new File("/generator/generatorConfig.xml");
		InputStream is = Surrogate.Generator.class.getResourceAsStream("/generator/generatorConfig.xml");

		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(is);
		is.close();

		DefaultShellCallback callback = new DefaultShellCallback(overwrite);

		//创建MBG
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
				callback, warnings);
		//执行生成代码
		myBatisGenerator.generate(null);

	}
	public static void main(String[] args) throws Exception {
		try {
			GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
			generatorSqlmap.generator();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
